package com.laiat.yamba;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class TwitterResultReceiver extends BroadcastReceiver {

	private static final String TAG = TwitterResultReceiver.class.getSimpleName();

	private Activity activity;
	
	public TwitterResultReceiver(Activity activity) {
		super();
		this.activity = activity;
	}
	
	
	@Override
	public void onReceive(Context context, Intent intent) {
		
		Bundle extraBundles = intent.getExtras();
		
		Exception oauthLoginException = (Exception)extraBundles.get(YambaApplication.OAUTH_LOGIN_EXCEPTION);
		if (oauthLoginException != null) {
			Log.d(TAG, "Received OAuth Login Exception broadcast msg:" + oauthLoginException.getMessage());
			Toast.makeText(activity, "Twitter Login Failed", Toast.LENGTH_LONG).show();
		} else {
		
			String text = intent.getStringExtra(YambaApplication.OAUTH_TEXT);
			if (text == null) {
				text = "Error occurred during call to Twitter.";
			}
			
			Toast.makeText(activity, text, Toast.LENGTH_LONG).show();
		}
		
		
		
	}

}
